/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * callbacks.c
 * Copyright (C) chaitanya chandel 2009 <cchandel@yahoo.com>
 * 
 * callbacks.c is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * callbacks.c is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#define _GNU_SOURCE
#include "callbacks.h"
#include "dbsqlite.h"
#include <stdio.h>
#include <unistd.h>
#include <Ecore_X.h>
#include <time.h>
#include <linux/rtc.h>
#include <fcntl.h>
#include <sys/ioctl.h>

char log_type[25];

int clock_func(void *data)
{
	time_t curtime;
	struct tm *loctime;
	char dt[6], yy[9];
	
	curtime = time (NULL);
	loctime = localtime (&curtime);
	strftime(dt, 20, f_time, loctime);
	edje_object_part_text_set(main_edje, "time", dt);
	strftime(yy, 20, f_date, loctime);
	edje_object_part_text_set(main_edje, "date", yy);
	return 1;
}

int timer_func(void *data)
{
	//set the win value
	focus_win = ecore_x_window_focus_get();
	//check focus chaged
	if (my_win == focus_win) {
		tim_cnt ++;
		if (tim_cnt < 15) return 1;
	}
	elm_win_title_set(win, "Launcher");
	return 0;
}

void close_win(void *data, Evas_Object *obj, void *event_info)
{
	Evas_Object *win_dow = data;
	//close the window
	evas_object_del(win_dow);
	win_dow = NULL;
}

void cancel_button_clicked(void *data, Evas_Object *obj, void *event_info)
{
	Winlist *wl = data;
	//clear the list
	if (wl->li) {
		if (wl->li == list) select_category (cur_cat, NULL, NULL);
		elm_genlist_clear(wl->li);
	}
	//close the window
	evas_object_del(wl->win);
}

static int
file_select(const struct dirent *entry)
{
	if ((strcmp(entry->d_name, ".") == 0) ||
		(strcmp(entry->d_name, "..") == 0) || 
		(strncmp(entry->d_name,".",1) == 0))
						 return 0;
	else return 1;
}

void load_dir(Evas_Object *li, char *direc)
{
	int n, i;
    struct dirent **eps;
	char buf[255], old_dir[255], buf1[255];
	Elm_Genlist_Item *dir_list=NULL;
    strcpy(old_dir, direc);
	
	snprintf(buf, sizeof(buf), "%s/folder.png", launcher_dir);
	snprintf(buf1, sizeof(buf1), "%s/generic.png", launcher_dir);

	n = scandir (old_dir, &eps, file_select, alphasort);
    if (n > 0) {
	    //clear the list
		elm_genlist_clear(li);
	   	for (i = 0; i < n; ++i) {
			if(strcmp(old_dir, "/") == 0) sprintf(dir_gl_entry[i].path, "/%s", eps[i]->d_name);
			else sprintf(dir_gl_entry[i].path, "%s/%s", old_dir, eps[i]->d_name);
			dir_gl_entry[i].type = eps[i]->d_type;
			elm_genlist_item_append(li, &itc_dir_list, &dir_gl_entry[i], NULL, 
									ELM_GENLIST_ITEM_NONE, NULL, NULL);
		}
	}
    else return;
    free(eps);
	dir_list = elm_genlist_first_item_get(li);
	elm_genlist_item_selected_set(dir_list ,1);
}

void dir_list_select(void *data, Evas_Object *obj, void *event_info)
{
	Evas_Object *li = data;
	Elm_Genlist_Item *item = (Elm_Genlist_Item *)elm_genlist_selected_item_get(li);
	_dir *dir_gl = (_dir *)elm_genlist_item_data_get(item);
	load_dir(li, dir_gl->path);
}

void up_button_clicked(void *data, Evas_Object *obj, void *event_info)
{
    char tystr[255], ty[255];
    int i, flag=0;    
    Evas_Object *l = data;
    Elm_Genlist_Item *item = (Elm_Genlist_Item *)elm_genlist_selected_item_get(l);
    _dir *dir_gl = (_dir *)elm_genlist_item_data_get(item);
	char *path = dir_gl->path;
	
    if(strcmp(path, "/") == 0) strcpy(tystr, path);
    else {
        int n = strlen(path);
        strcpy(ty, path);
        for(i=n-1; i>0; i--) {
            if (ty[i] == '/') {
                if (flag == 1) break;
                else flag = 1;
            }
        }
        if (i == 0) strcpy(tystr, "/");
        else {
            strncpy(tystr, ty, i);
            tystr[i] = '\0';
        }
    }
	load_dir(l, tystr);
}

void home_button_clicked(void *data, Evas_Object *obj, void *event_info)
{
	Evas_Object *l = data;

	load_dir(l, "/usr/share/wallpapers");
}

void add_dir_button_clicked(void *data, Evas_Object *obj, void *event_info)
{
	char *direc;
	static Winlist wl;

	Evas_Object *l = data;
	Elm_Genlist_Item *item = (Elm_Genlist_Item *)elm_genlist_selected_item_get(l);
	_dir *dir_gl = (_dir *)elm_genlist_item_data_get(item);
	direc = dir_gl->path;
	strcpy(wall_path, direc);
	wl.win = dir_browser_page_win;
	wl.li = NULL;
	cancel_button_clicked(&wl, NULL, NULL);
	elm_bg_file_set(bg, wall_path, NULL);
	save_wallpaper();
}

 void app_select(void *data, Evas_Object *obj, void *event_info)
{
	Elm_Genlist_Item *item;
	_Cat *cat=NULL;

	Evas_Object *li = data;
	item = (Elm_Genlist_Item *)elm_genlist_selected_item_get(li);
	cat = (_Cat *)elm_genlist_item_data_get(item);
	elm_button_label_set(cat_bt, cat->cat);
	elm_label_label_set(app_lb, cat->app);
}

void seq_move_up(void *data, Evas_Object *obj, void *event_info)
{
	Elm_Genlist_Item *prev_item, *item;
	char *ty = (char *)data;
	
	//get selected item
	item = (Elm_Genlist_Item *)elm_genlist_selected_item_get(seq_list);
	if (!item) return;
	char *d1 = (char *)elm_genlist_item_data_get(item);

	//get previous item
	prev_item = elm_genlist_item_prev_get(item);
	if (!prev_item) return;
	
	//delete item
	elm_genlist_item_del(item);
	item = elm_genlist_item_insert_before(seq_list, &itc_seq_list, d1, prev_item, 
		                        ELM_GENLIST_ITEM_NONE, NULL, NULL);
	elm_genlist_item_selected_set(item, 1);
	set_seq_db(seq_list, ty);
}

void seq_move_down(void *data, Evas_Object *obj, void *event_info)
{
	Elm_Genlist_Item *next_item, *item;
	char *ty = (char *)data;
	
	//get selected item
	item = (Elm_Genlist_Item *)elm_genlist_selected_item_get(seq_list);
	if (!item) return;
	char *d1 = (char *)elm_genlist_item_data_get(item);

	//get previous item
	next_item = elm_genlist_item_next_get(item);
	if (!next_item) return;
	
	//delete item
	elm_genlist_item_del(item);
	item = elm_genlist_item_insert_after(seq_list, &itc_seq_list, d1, next_item, 
		                        ELM_GENLIST_ITEM_NONE, NULL, NULL);
	elm_genlist_item_selected_set(item, 1);
	set_seq_db(seq_list, ty);
}

void done_clicked(void *data, Evas_Object *obj, void *event_info)
{
	static Winlist wl1;

	Winlist *wl = data;
	//change_seq(wl->li);

	//TODO:delete items from toolbar

	//TODO:add toolbar items

	//close the window
	wl1.win = wl->win;
	wl1.li = wl->li;
	cancel_button_clicked (&wl1, NULL, NULL);
}

void set_call_clicked(void *data, Evas_Object *obj, void *event_info)
{
	char *ty;
	Evas_Object *en = data;

	//get data from entry
	char *en_data = (char *)elm_entry_entry_get(en);
	ty = strtok(en_data, "<");
	if (strcmp(ty, "") == 0) {
		elm_entry_entry_set(en, app_calls);
		return;
	}
	strcpy(app_calls, ty);
}

void set_sms_clicked(void *data, Evas_Object *obj, void *event_info)
{
	char *ty;
	Evas_Object *en = data;

	//get data from entry
	char *en_data = (char *)elm_entry_entry_get(en);
	ty = strtok(en_data, "<");
	if (strcmp(ty, "") == 0) {
		elm_entry_entry_set(en, app_sms);
		return;
	}
	strcpy(app_sms, ty);
}

void set_date_format(void *data, Evas_Object *obj, void *event_info)
{
	char *ty;
	Evas_Object *en = data;

	//get data from entry
	char *en_data = (char *)elm_entry_entry_get(en);
	ty = strtok(en_data, "<");
	strcpy(f_date, ty);
}

void set_time_format(void *data, Evas_Object *obj, void *event_info)
{
	char *ty;
	Evas_Object *en = data;

	//get data from entry
	char *en_data = (char *)elm_entry_entry_get(en);
	ty = strtok(en_data, "<");
	strcpy(f_time, ty);
}

void set_bt_add(void *data, Evas_Object *obj, void *event_info)
{
	char *ty;
	Evas_Object *en = data;

	//get data from entry
	char *en_data = (char *)elm_entry_entry_get(en);
	ty = strtok(en_data, "<");
	strcpy(hs_add, ty);
}

void set_cb_subs(void *data, Evas_Object *obj, void *event_info)
{
	char *ty;
	Evas_Object *en = data;

	//get data from entry
	char *en_data = (char *)elm_entry_entry_get(en);
	ty = strtok(en_data, "<");
	strcpy(cb_subs, ty);
}

void create_cat_hover(void)
{
	Evas_Object *bt;
	bt = elm_button_add(win);
	
	if (cat_hv_bx) evas_object_del(cat_hv_bx);
	cat_hv_bx = elm_box_add(win);
	add_hs_items (win, cat_hv_bx, bt, 1);
	evas_object_show(cat_hv_bx);
	elm_hover_content_set(hs, "bottom", cat_hv_bx);
	evas_object_hide(hs);
}

void cat_dialog_add(void *data, Evas_Object *obj, void *event_info)
{
	char *ty, *ty_data;
	Evas_Object *en = data;

	//get data from entry and add to category table
	char *_cat = (char *)elm_entry_entry_get(en);
	ty = strtok(_cat, "<");
	if (strcmp(ty, "") == 0) return;
	ty_data = strdup(ty);
	add_category(ty);
	elm_genlist_item_append(cat_list, &itc2, ty_data, NULL, ELM_GENLIST_ITEM_NONE,
								  NULL, NULL);
	evas_object_del(cat_dialog);
	create_cat_hover();
}

void cat_win_del(void *data, Evas_Object *obj, void *event_info)
{
	Evas_Object *c_win = data;
	evas_object_del(c_win);
}

void cat_dialog_ren(void *data, Evas_Object *obj, void *event_info)
{
	char *ty, *ty_data, *old;
	Evas_Object *en = data;
	Elm_Genlist_Item *item, *new_item;
	
	//get data from entry and rename the selected category
	item = elm_genlist_selected_item_get(cat_list);
	old = (char *)elm_genlist_item_data_get(item);
	char *_cat = (char *)elm_entry_entry_get(en);
	ty = strtok(_cat, "<");
	if (strcmp(ty, "") == 0) return;
	ty_data = strdup(ty);
	ren_category(old ,ty);
	new_item = elm_genlist_item_insert_after(cat_list, &itc2, ty_data, item, ELM_GENLIST_ITEM_NONE,
								  NULL, NULL);
	elm_genlist_item_del(item);
	elm_genlist_item_selected_set(new_item ,1);
	evas_object_del(cat_dialog);
	//use the next line only id using a hover
	//create_cat_hover ();
	//refresh launcher apps
	select_category (cur_cat, NULL, NULL);
}

void del_cat_button_clicked(void *data, Evas_Object *obj, void *event_info)
{
	Evas_Object *li = data;
	Elm_Genlist_Item *item = (Elm_Genlist_Item *)elm_genlist_selected_item_get(li);
	char *_cat = (char *)elm_genlist_item_data_get(item);
	//delete category from db
	del_category(_cat);
	//remove item from list
	elm_genlist_item_del(item);
	create_cat_hover ();
	//refresh launcher apps
	select_category (cur_cat, NULL, NULL);
}

void icon_home_clicked(void *data, Evas_Object *obj, void *event_info)
{
	int ret, no;
	char cmd[255], chk[255], *ty, *line, *tystr;
	FILE *ps_file;
	size_t len = 0;
	ssize_t read = 0;

	line = (char *) malloc (len+ 1);
	//get the command to launch
	no = (int* )data;
	sprintf(cmd, "%s", path_home[no]);
	//check for internal apps
	if(strcmp(cmd, "int_sms") == 0) {
		sms_app(NULL, NULL, NULL); 
		return;
	}
	if(strcmp(cmd, "int_log") == 0) {
		tystr = "Outgoing";
		log_app(tystr, NULL, NULL); 
		return;
	}	
	if(strcmp(cmd, "int_con") == 0) {
		contacts_app("", NULL, NULL); 
		return;
	}	
	ty = strdup(cmd);

	//get pid of command
	sprintf(chk, "ps -C '%s' -o pid= > /tmp/ps.intone", ty);
	ret = system (chk);

	//open file to read data
	ps_file =  fopen("/tmp/ps.intone", "r");
	read = getline(&line, &len, ps_file);
	len = atoi(line);
	
	if (!len) {
		ecore_exe_run(cmd, NULL);
		printf("%s\n", cmd);
		//show the starting up indication
		elm_win_title_set(win, "LOADING..");
		//set the win value
		my_win = ecore_x_window_focus_get();
		//set the timer
		timer1 = ecore_timer_add(1.0, timer_func, NULL);
	}
	free(line);
}

void icon_clicked(void *data, Evas_Object *obj, void *event_info)
{
	int ret, no;
	char cmd[255], chk[255], *ty, *line, *tystr;
	FILE *ps_file;
	size_t len = 0;
	ssize_t read = 0;

	line = (char *) malloc (len+ 1);
	//get the command to launch
	no = (int* )data;
	sprintf(cmd, "%s", path[no]);
	//check for internal apps
	if(strcmp(cmd, "int_sms") == 0) {
		sms_app(NULL, NULL, NULL); 
		return;
	}
	if(strcmp(cmd, "int_log") == 0) {
		tystr = "Outgoing";
		log_app(tystr, NULL, NULL); 
		return;
	}	
	if(strcmp(cmd, "int_con") == 0) {
		contacts_app("", NULL, NULL); 
		return;
	}	
	ty = strdup(cmd);

	//get pid of command
	sprintf(chk, "ps -C '%s' -o pid= > /tmp/ps.intone", ty);
	ret = system (chk);

	//open file to read data
	ps_file =  fopen("/tmp/ps.intone", "r");
	read = getline(&line, &len, ps_file);
	len = atoi(line);
	
	if (!len) {
		ecore_exe_run(cmd, NULL);
		printf("%s\n", cmd);
		//show the starting up indication
		elm_win_title_set(win, "LOADING..");
		//set the win value
		my_win = ecore_x_window_focus_get();
		//set the timer
		timer1 = ecore_timer_add(1.0, timer_func, NULL);
	}
	free(line);
}

void set_category(void *data, Evas_Object *obj, void *event_info)
{
	char *ca = (char *)data;
	Elm_Genlist_Item *item;
	_Cat *cat;

	evas_object_hide(hv);
	elm_button_label_set(cat_bt, ca);

	item = (Elm_Genlist_Item *)elm_genlist_selected_item_get(list);
	cat = (_Cat *)elm_genlist_item_data_get(item);
	update_category(cat->app, ca);
	strcpy(cat->cat, ca);
	elm_genlist_item_update(item);
}

void select_category(void *data, Evas_Object *obj, void *event_info)
{
	Evas_Object *ic, *bx, *lab;
	int no, x, y, no_lines, rem, cmp=0;
	char *cat = (char *)data, /**cat,*/ buf[255], ty[255];
	//cat = strdup(ca);

	//set global cat var
	strcpy(cur_cat, cat);
	//delete table
	if(tb) evas_object_del(tb);
	//delete scroller if it exists
	if(sc) evas_object_del(sc);
	//get the apps in this category
	no = get_apps(cat);
	if (no > 16) {
		//add scroller
		sc = elm_scroller_add(show_apps_win);
		elm_scroller_content_min_limit(sc, 1, 0);
		elm_scroller_bounce_set(sc, 0, 0);
		elm_scroller_policy_set(sc, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
		evas_object_size_hint_weight_set(sc, 1.0, 1.0);
		evas_object_size_hint_align_set(sc, 0.0, 0.0);
		elm_layout_content_set(ly_right, "table", sc);
	}
	
	//add a table
	tb = elm_table_add(show_apps_win);
	evas_object_size_hint_weight_set(tb, 1.0, 1.0);
	evas_object_size_hint_align_set(tb, 0.0, 0.0);
	if (no < 17) elm_layout_content_set(ly_right, "table", tb);
	else {
		evas_object_size_hint_align_set(tb, 0.0, 0.0);
		elm_scroller_content_set(sc, tb);
	}
	evas_object_show(tb);
	if (no > 16) evas_object_show(sc);
	
	//populate the table
	no_lines = no / 4;
	rem = no%4;
	if (rem > 0) no_lines ++;
	for (y=0; y< no_lines; y++) {
		for (x=0; x<4; x++) {
			cmp = x + y*4;
			if (cmp > no-1) break;
			bx = elm_box_add(show_apps_win);
			evas_object_show(bx);
	
			ic = elm_icon_add(show_apps_win);
			strcpy(buf, icon[cmp]);
			elm_icon_file_set(ic, buf, NULL);
			elm_icon_scale_set(ic, 1, 1);
			evas_object_size_hint_min_set(ic, 80, 80);
			evas_object_show(ic);
			elm_box_pack_end(bx, ic);			

			lab = elm_label_add(show_apps_win);
			if (strlen(name[cmp]) < 9) strcpy(ty, name[cmp]);
			else {
				strncpy(ty, name[cmp], 6);
				ty[6] = '.';
				ty[7] = '.';
				ty[8] = '\0';
			}	
			elm_label_label_set(lab, ty);
			elm_box_pack_end(bx, lab);
			evas_object_show(lab);
                        elm_table_pack(tb, bx , x, y, 1, 1);
			evas_object_smart_callback_add(ic, "clicked", icon_clicked, (void *)cmp);
		}
	}
}

void ic_calls_clicked(void *data, Evas_Object *obj, void *event_info)
{
	char buf[255], *ty;
	m_calls = 0;
	if (reminder_timer) ecore_timer_del(reminder_timer);
	pend_call = 0;
	ty = "Missed";
	if (int_log) log_app(ty, NULL, NULL);
	else ecore_exe_run(app_calls, NULL);
	//show the starting up indication
	elm_win_title_set(win, "LOADING..");
	//set the win value
	my_win = ecore_x_window_focus_get();
	//set the timer - and cater for the timer being set by a missed sms
	if (!reminder_timer) reminder_timer = ecore_timer_add(1.0, timer_func, NULL);	

	snprintf(buf, sizeof(buf), "%s/none.png", "/usr/share/launcher");
	elm_icon_file_set(ic_calls, buf, NULL);
	elm_icon_scale_set(ic_calls, 1, 1);
	evas_object_size_hint_min_set(ic_calls, 80, 80);
	evas_object_hide(call_lb);
}

void ic_sms_clicked(void *data, Evas_Object *obj, void *event_info)
{
	char buf[255];
	m_sms = 0;
	if (reminder_timer) ecore_timer_del(reminder_timer);
	pend_sms = 0;
	if (int_sms) sms_app(NULL, NULL, NULL);
	else ecore_exe_run(app_sms, NULL);
	//show the starting up indication
	elm_win_title_set(win, "LOADING..");
	//set the win value
	my_win = ecore_x_window_focus_get();
	//set the timer - and cater for the timer being set by a missed call
	if (!reminder_timer) reminder_timer = ecore_timer_add(1.0, timer_func, NULL);

	snprintf(buf, sizeof(buf), "%s/none.png", "/usr/share/launcher");
	elm_icon_file_set(ic_sms, buf, NULL);
	elm_icon_scale_set(ic_sms, 1, 1);
	evas_object_size_hint_min_set(ic_sms, 80, 80);
	evas_object_hide(sms_lb);
}

void run_app(void)
{
	printf("launching %s\n", noti_launch[0]);
	ecore_exe_run(noti_launch[0], NULL);
}
/**************************************
 
 for notifications - we have a service that accepts the following parameters
  - message (to be shown) - string < 255 char
  - app name - string < 35 char
  - app to run on clicking this message - string < 255 char
 the reminders are the same as for missed calls and messages. The sound is different

  additional variables counter
**************************************/

void show_noti(void *data, Evas_Object *obj, void *event_info)
{
	char buf[255];

	printf("in show_noti\n");
	snprintf(buf, sizeof(buf), "%s/settings.png", "/usr/share/launcher");
	elm_icon_file_set(ic_noti, buf, NULL);
	elm_icon_scale_set(ic_noti, 1, 1);
	evas_object_size_hint_min_set(ic_noti, 80, 80);
}

void show_log(void *data, Evas_Object *obj, void *event_info)
{
	elm_genlist_clear(log_list);
	strcpy(log_type, (char *)data);
	get_calls();
}

void show_cat_contacts(void *data, Evas_Object *obj, void *event_info)
{
	elm_genlist_clear(contact_list);
	//strcpy(log_type, (char *)data);
	char *ty = (char *) data;
	if (strcmp(ty, "Edit Cat") == 0) manage_contact_cat();
	else if (strcmp(ty, "Set Cat") == 0) set_contact_cat();
	else get_cat_contacts(ty);
}

void cb_sms_clicked(void *data, Evas_Object *obj, void *event_info)
{
	int_sms = elm_check_state_get(cb_sms);
	select_category (cur_cat, NULL, NULL);
}

void cb_log_clicked(void *data, Evas_Object *obj, void *event_info)
{
	int_log = elm_check_state_get(cb_log);
	select_category (cur_cat, NULL, NULL);
}

void cb_con_clicked(void *data, Evas_Object *obj, void *event_info)
{
	int_con = elm_check_state_get(cb_con);
	select_category (cur_cat, NULL, NULL);
}

void cb_channel_clicked(void *data, Evas_Object *obj, void *event_info)
{
	show_c_no = elm_check_state_get(cb_channel);
}

void cb_hs_clicked(void *data, Evas_Object *obj, void *event_info)
{
	reconnect_bt = elm_check_state_get(cb_hs);
}

void update_letter_count (void *data, Evas_Object *obj, void *event_info)
{
	char ty[20];
	int me=0;
	Winlist *c_d = (Winlist *)data;

	l_co = strlen(elm_entry_entry_get(c_d->li));
	me = (l_co/160) +1;
	sprintf(ty, "part %d: char %d", me, ((160 * (me - 1)) + 160-l_co));
	elm_bubble_info_set(c_d->win, ty);
}

void add_sent_sms(int i, int retry, int ind)
{
	char dt[40], format[40], content[510], ty[255], buf[255], *tok;
	Evas_Object *ic, *bb, *av, *bt, *hbox;
	struct tm *loctime;

	//set the date time
	time_t p_time;
	time(&p_time);
	loctime = localtime (&p_time);
	sprintf(format, "%s %s", f_date, f_time);
	strftime(dt, 40, format, loctime);
	
	//set the content
	sprintf(content, "%s", elm_entry_entry_get(Re.en));

	//add bubble with sent sms data
	ic = elm_icon_add(win_sms);
	bb = elm_bubble_add(win_sms);
	elm_bubble_corner_set(bb, "top_right");
	if (retry) snprintf(buf, sizeof(buf), "%s/err_sms.png", "/usr/share/launcher");
	else snprintf(buf, sizeof(buf), "%s/sms_out.png", "/usr/share/launcher");
	elm_icon_file_set(ic, buf, NULL);
	elm_icon_scale_set(ic, 1, 1);
	evas_object_size_hint_min_set(ic, 45, 45);
	evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
		
	strcpy(ty, Con_Sms[ind].name);
	elm_bubble_label_set(bb, ty);
	elm_bubble_info_set(bb, dt);
	elm_bubble_icon_set(bb, ic);
	evas_object_show(ic);
	evas_object_size_hint_weight_set(bb, 1.0, 1.0);
	evas_object_size_hint_align_set(bb, -1.0, 0.0);
	
	av = elm_anchorblock_add(win_sms);
	elm_anchorblock_hover_style_set(av, "popout");
	elm_anchorblock_hover_parent_set(av, win_sms);
	tok = elm_entry_utf8_to_markup(content);
	elm_anchorblock_text_set(av, content);
	evas_object_smart_callback_add(av, "anchor,clicked", my_anchorblock_anchor, av);
	elm_bubble_content_set(bb, av);
	evas_object_show(av);
	
	elm_box_pack_start(vbox_sms, bb);
	evas_object_show(bb);

	hbox = elm_box_add(win_sms);
	elm_box_homogenous_set(hbox ,1);
	elm_box_horizontal_set(hbox, 1);
	evas_object_size_hint_weight_set(hbox, 1.0, 0.0);
	evas_object_size_hint_align_set(hbox, 1.0, 0.0);
	elm_box_pack_after(vbox_sms, hbox, bb);
	evas_object_show(hbox);

	//set up sms_bb values
	strcpy(sms_bb[i].content, content);
	strcpy(sms_bb[i].path, Re.path);
	sms_bb[i].stamp = p_time;
	sms_bb[i].ic = ic;
	sms_bb[i].bb = bb;
	sms_bb[i].ret_bt = NULL;
	
	if (retry) {
		bt = elm_button_add(win_sms);
		elm_button_label_set(bt, " Retry ");
		evas_object_size_hint_weight_set(bt, 0.0, 0.0);
		evas_object_size_hint_align_set(bt, 1.0, 0.0);
		elm_box_pack_end(hbox, bt);
		evas_object_show(bt);
		sms_bb[i].ret_bt = bt;
		evas_object_smart_callback_add(bt, "clicked", (void *)resend_sms, &sms_bb[i]);
	}
	
	//add forward button
	bt = elm_button_add(win_sms);
	elm_button_label_set(bt, "Forward");
	evas_object_size_hint_weight_set(bt, 0.0, 0.0);
	evas_object_size_hint_align_set(bt, 1.0, 0.0);
	elm_box_pack_end(hbox, bt);
	evas_object_show(bt);
	//evas_object_smart_callback_add(bt, "clicked", (void *)del_single_sms, &sms_bb[i]);
	sms_bb[i].fwd_bt = bt;
	
	bt = elm_button_add(win_sms);
	elm_button_label_set(bt, "Delete");
	evas_object_size_hint_weight_set(bt, 0.0, 0.0);
	evas_object_size_hint_align_set(bt, 1.0, 0.0);
	elm_box_pack_end(hbox, bt);
	evas_object_show(bt);
	sms_bb[i].del_bt = bt;
	evas_object_smart_callback_add(bt, "clicked", (void *)del_single_sms, &sms_bb[i]);

	//add_sms_conv();
}

void set_con_category(char *cat)
{
	strcpy(con_cat, cat);
	evas_object_hide(con_hv);
	elm_button_label_set(contact_cat_bt, cat);
}

void jump_button_clicked(void *data, Evas_Object *obj, void *event_info)
{
	char n[1], *c = (char *)data;
	_contact *con;
	
	Elm_Genlist_Item *item = elm_genlist_first_item_get(contact_list);
	if(!item) return;
	while ((con = (_contact *)elm_genlist_item_data_get(item))) {
		//cater for lower case names by converting 1st char to upper case
		strncpy(n, con->name, 1);
		n[0] = toupper(n[0]);
		n[1] = '\0';
		//printf("%s\n", n);
		if (strcmp(n, c) == 0 || strcmp(n, c) >1) break;
		else item = elm_genlist_item_next_get(item);
		if(!item) {
			item = elm_genlist_last_item_get(contact_list);
			break;
		}
	}
	elm_genlist_item_top_show(item);
	evas_object_del(jump_win);
}

void jump(void *data, Evas_Object *obj, void *event_info)
{
	Evas_Object *bg, *button, *tb;
	char alpha[1], *bet;
	int i, j;
	
	jump_win = elm_win_add(NULL, "log", ELM_WIN_BASIC);
	elm_win_title_set(jump_win, "Jump");
	elm_win_autodel_set(jump_win, 1);
	
	//add background
	bg = elm_bg_add(jump_win);
	elm_win_resize_object_add(jump_win, bg);
	evas_object_size_hint_weight_set(bg, 1.0, 1.0);
	evas_object_show(bg);

	//add a table
	tb = elm_table_add(jump_win);
	elm_win_resize_object_add(jump_win, tb);
	evas_object_size_hint_weight_set(tb, 1.0, 1.0);
	evas_object_show(tb);

	//add alphabet buttons
	alpha[1] = '\0';
	for(j=0; j<5;j++) {
		for (i=0; i<5; i++) {
			button = elm_button_add(jump_win);
			alpha[0] = 'A' + ((5 * j) + i);
			elm_button_label_set(button, alpha);
			evas_object_size_hint_weight_set(button, 1.0, 1.0);
			evas_object_size_hint_align_set(button, -1.0, -1.0);
			elm_table_pack(tb, button, i, j, 1, 1);
			evas_object_show(button);
			bet = strdup(alpha);
			evas_object_smart_callback_add(button, "clicked", jump_button_clicked, bet);
		}
	}
	// make window full screen
	evas_object_resize(jump_win, 480, 640);
	evas_object_show(jump_win);
}

void take_action(void *data, Evas_Object *obj, void *event_info)
{
	Evas_Object *li = (Evas_Object *)data;
	
	Elm_Genlist_Item *item = elm_genlist_selected_item_get(li);
	pass_data = (_act_element *)elm_genlist_item_data_get(item);
	if(strcmp(pass_data->action, "Call") == 0) place_call(pass_data->num);
	else if(strcmp(pass_data->action, "Send SMS") == 0) new_sms(pass_data, NULL, NULL);
	else if(strcmp(pass_data->action, "Add to Contacts") == 0) add_edit_contact(pass_data, NULL, NULL);
	else if(strcmp(pass_data->action, "Add to Contacts SMS") == 0) add_edit_contact(pass_data, NULL, NULL);
	else if(strcmp(pass_data->action, "Edit Contact") == 0) add_edit_contact(pass_data, NULL, NULL);
	else if(strcmp(pass_data->action, "Delete Contact") == 0) del_contact(pass_data->path);
	else if(strcmp(pass_data->action, "Delete Log Entry") == 0) del_log_entry(pass_data->path);
}

char *act_label_get(const void *data, Evas_Object *obj, const char *part)
{
	char tystr[255], *ty;
	
	_act_element *da = (_act_element *)data;
	strcpy(tystr, da->action);

	ty = strdup(tystr);
	return (ty);
}

Evas_Object *act_icon_get(const void *data, Evas_Object *obj, const char *part)
{
	_act_element *da = (_act_element *)data;
	char buf[255];

	if (!strcmp(part, "elm.swallow.icon")) {
		Evas_Object *ic = elm_icon_add(obj);
		if (strcmp(da->action, "Edit Contact") == 0) 
			snprintf(buf, sizeof(buf), "/usr/share/launcher/edit_contact.png");
		else if (strcmp(da->action, "Add to Contacts") == 0) 
			snprintf(buf, sizeof(buf), "/usr/share/launcher/add_contact.png");
		else if (strcmp(da->action, "Delete Contact") == 0) 
			snprintf(buf, sizeof(buf), "/usr/share/launcher/del_contact.png");
		else if (strcmp(da->action, "Send SMS") == 0) 
			snprintf(buf, sizeof(buf), "/usr/share/launcher/sms_out.png");
		else if (strcmp(da->action, "Call") == 0) 
			snprintf(buf, sizeof(buf), "/usr/share/launcher/call.png");
		elm_icon_file_set(ic, buf, NULL);
		evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
		return ic;
	}
	return NULL;
}

Eina_Bool act_state_get(const void *data, Evas_Object *obj, const char *part)
{
   return 0;
}

void act_del (const void *data, Evas_Object *obj)
{
}

void show_actions(void *data, Evas_Object *obj, void *event_info)
{
	Evas_Object *bg, *vbox, *fr, *lb, *button, *vbox1, *act_list;
	char ty[255], *tok=NULL;
	static Winlist wl;
	Elm_Genlist_Item *item;
	_act_data *da = (_act_data *)data;
	_Log *p_log = NULL;
	_contact *con = NULL;
	
	Evas_Object *li = da->li;
	item = (Elm_Genlist_Item *)elm_genlist_selected_item_get(li);
	if (!item) return;
	if (strcmp(da->type, "log") == 0) p_log = (_Log *)elm_genlist_item_data_get(item);
	else if (strcmp(da->type, "con") == 0) con = (_contact *) elm_genlist_item_data_get(item);
	
	act_win = elm_win_add(NULL, "act", ELM_WIN_BASIC);
	elm_win_title_set(act_win, "Actions");
	elm_win_autodel_set(act_win, 1);
	
	//add background
	bg = elm_bg_add(act_win);
	elm_win_resize_object_add(act_win, bg);
	evas_object_size_hint_weight_set(bg, 1.0, 1.0);
	evas_object_show(bg);
	
	//add vbox 
	vbox = elm_box_add(act_win);
	elm_win_resize_object_add(act_win, vbox);
	evas_object_size_hint_weight_set(vbox, 1.0, 1.0);
	evas_object_show(vbox);

	//add a frame
	fr = elm_frame_add(act_win);
	elm_object_style_set(fr, "outdent_top");
	evas_object_size_hint_weight_set(fr, 0.0, 0.0);
	evas_object_size_hint_align_set(fr, 0.0, -1.0);
	elm_box_pack_end(vbox, fr);
	evas_object_show(fr);

	//add a hbox
	vbox1 = elm_box_add(act_win);
	evas_object_size_hint_weight_set(vbox1, 1.0, 1.0);
	elm_frame_content_set(fr, vbox1);
	evas_object_show(vbox1);

	if (strcmp(da->type, "log") == 0) {
		// add a label
		lb = elm_label_add(act_win);
		elm_label_label_set(lb, p_log->name);
		elm_box_pack_end(vbox1, lb);
		evas_object_show(lb);

		// add a label
		lb = elm_label_add(act_win);
		elm_label_label_set(lb, p_log->num);
		elm_box_pack_end(vbox1, lb);
		evas_object_show(lb);

		// add a label
		lb = elm_label_add(act_win);
		elm_label_label_set(lb, p_log->timestamp);
		elm_box_pack_end(vbox1, lb);
		evas_object_show(lb);
	}

	if (strcmp(da->type, "con") == 0) {
		// add a label
		lb = elm_label_add(act_win);
		elm_label_label_set(lb, con->name);
		elm_box_pack_end(vbox1, lb);
		evas_object_show(lb);

		//remove the prefix tel:
		strcpy(ty, con->phone);
		tok = strchr(ty, ':');
		if (tok == NULL) tok = ty;
		else tok++;
		
		// add a label
		lb = elm_label_add(act_win);
		elm_label_label_set(lb, tok);
		elm_box_pack_end(vbox1, lb);
		evas_object_show(lb);
	}
	
	//add list to vbox now
	act_list = elm_genlist_add(act_win);
	//elm_genlist_bounce_set(act_list, 0, 0);
	elm_genlist_always_select_mode_set(act_list, 1);
	evas_object_size_hint_weight_set(act_list, 1.0, 1.0);
	evas_object_size_hint_align_set(act_list, -1.0, -1.0);
	elm_list_multi_select_set(act_list, 0);
	elm_box_pack_end(vbox, act_list);
	evas_object_show(act_list);
	evas_object_smart_callback_add(act_list, "selected", take_action, act_list);

	if (strcmp(da->type, "log") == 0) {
		strcpy (act_el[0].name, p_log->name);
		strcpy (act_el[0].num, p_log->num);
		strcpy (act_el[0].path, "");
		strcpy (act_el[0].action, "Call");
		elm_genlist_item_append(act_list, &itc_act, &act_el[0], NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
		strcpy (act_el[1].name, p_log->name);
		strcpy (act_el[1].num, p_log->num);
		strcpy (act_el[1].path, "");
		strcpy (act_el[1].action, "Send SMS");
		elm_genlist_item_append(act_list, &itc_act, &act_el[1], NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
		strcpy (act_el[2].name, p_log->name);
		strcpy (act_el[2].num, p_log->num);
		strcpy (act_el[2].path, "");
		strcpy (act_el[2].action, "Add to Contacts");
		elm_genlist_item_append(act_list, &itc_act, &act_el[2], NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
		strcpy (act_el[3].name, p_log->name);
		strcpy (act_el[3].num, p_log->num);
		strcpy (act_el[3].path, p_log->path);
		strcpy (act_el[3].action, "Edit Contact");
		elm_genlist_item_append(act_list, &itc_act, &act_el[3], NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
		strcpy (act_el[4].name, p_log->name);
		strcpy (act_el[4].num, p_log->num);
		strcpy (act_el[4].path, p_log->path);
		strcpy (act_el[4].action, "Delete Log Entry");
		elm_genlist_item_append(act_list, &itc_act, &act_el[4], NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
	}
	else if (strcmp(da->type, "con") == 0) {
		strcpy (act_el[0].name, con->name);
		strcpy (act_el[0].num, tok);
		strcpy (act_el[0].path, con->path);
		strcpy (act_el[0].action, "Call");
		elm_genlist_item_append(act_list, &itc_act, &act_el[0], NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
		strcpy (act_el[1].name, con->name);
		strcpy (act_el[1].num, tok);
		strcpy (act_el[1].path, con->path);
		strcpy (act_el[1].action, "Send SMS");
		elm_genlist_item_append(act_list, &itc_act, &act_el[1], NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
		strcpy (act_el[2].name, con->name);
		strcpy (act_el[2].num, tok);
		strcpy (act_el[2].path, con->path);
		strcpy (act_el[2].action, "Edit Contact");
		elm_genlist_item_append(act_list, &itc_act, &act_el[2], NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
		strcpy (act_el[3].name, con->name);
		strcpy (act_el[3].num, tok);
		strcpy (act_el[3].path, con->path);
		strcpy (act_el[3].action, "Delete Contact");
		elm_genlist_item_append(act_list, &itc_act, &act_el[3], NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
	}
		
	//genlist class defs
	itc_act.item_style     	= "default";
	itc_act.func.label_get 	= act_label_get;
	itc_act.func.icon_get  	= act_icon_get;
	itc_act.func.state_get 	= act_state_get;
	itc_act.func.del      		= act_del;

	//add cancel button
	button = elm_button_add(act_win);
	elm_button_label_set(button, "Done");
	evas_object_size_hint_weight_set(button, 1.0, 0.0);
	evas_object_size_hint_align_set(button, -1.0, -1.0);
	elm_box_pack_end(vbox, button);
	evas_object_show(button);
	wl.win = act_win;
	wl.li = NULL;
	evas_object_smart_callback_add(button, "clicked", cancel_button_clicked, &wl);

	// make window full screen
	evas_object_resize(act_win, 480, 640);
	evas_object_show(act_win);
}

void rtc_set_time(void)
{
	int rtcfd, retval= 0;
	struct rtc_time rtc_tm;
	time_t now;
	struct tm *tm;

	rtcfd = open ("/dev/rtc", O_RDONLY);
	if (rtcfd ==  -1) {
		/* treat it as warning, may be should retry? */
		perror("/dev/rtc");
		errno = 0;
		return;
	}

	/* Set the RTC time/date */
	now = time (NULL);
	tm = gmtime (&now);
	rtc_tm.tm_mday = tm->tm_mday;
	rtc_tm.tm_mon = tm->tm_mon;
	rtc_tm.tm_year = tm->tm_year;
	rtc_tm.tm_hour = tm->tm_hour;
	rtc_tm.tm_min = tm->tm_min;
	rtc_tm.tm_sec = tm->tm_sec;
	retval = ioctl (rtcfd, RTC_SET_TIME, &rtc_tm);
	if (retval == -1) {
		perror ("ioctl");
		exit (errno);
	}
	close (rtcfd);
}

void del_sel_sms_con(void *data, Evas_Object *obj, void *event_info)
{
	const Eina_List *item;
	Evas_Object *li = (Evas_Object *) data;
	
	item = elm_genlist_selected_items_get(li);
	while((item = elm_genlist_selected_items_get(li)))
		elm_genlist_item_del(item->data);
}

void rescan_sms(void *data, Evas_Object *obj, void *event_info)
{
	char ty[255];
	strcpy(ty, "sms");
	
	clear_opim_db(ty);
	s_ts = 0.0;
	get_sms_data();
	match_sms_names();
	popup_message("SMS Data Rescanned!", NULL, 1);
}

void rescan_contacts(void *data, Evas_Object *obj, void *event_info)
{
	char ty[255];
	strcpy(ty, "contacts");
	
	clear_opim_db(ty);
	get_contacts_data();
	popup_message("Contacts Data Rescanned!", NULL, 1);
}

void rescan_calls(void *data, Evas_Object *obj, void *event_info)
{
	char ty[255];
	strcpy(ty, "calls");
	
	clear_opim_db(ty);
	c_ts = 0.0;
	get_calls_data();
	match_call_names();
	popup_message("Calls Data Rescanned!", NULL, 1);
}

static void
my_hover_bt_1(void *data, Evas_Object *obj, void *event_info)
{
   Evas_Object *hv = data;
   
   evas_object_show(hv);
}

char *gl_seq_label_get(const void *data, Evas_Object *obj, const char *part)
{
	_Cat *cat = (_Cat *)data;
	char tystr[255], *ty;
	
	sprintf(tystr, "%s", cat->app);
	ty = strdup(tystr);
	return (ty);
}

Evas_Object *gl_seq_icon_get(const void *data, Evas_Object *obj, const char *part)
{
	return NULL;
}

Eina_Bool gl_seq_state_get(const void *data, Evas_Object *obj, const char *part)
{
   return 0;
}

void gl_seq_del(const void *data, Evas_Object *obj)
{
	
}

void set_seq_page(char *type)
{
	//show the seq settings page
	char ty[255];
	Evas_Object *set_seq;
	set_seq = elm_win_add(NULL, "sequence", ELM_WIN_BASIC);
	elm_win_title_set(set_seq, "Set Sequence");

	Evas_Object *bg, *vbox, *hbox, *pref_lb, *fr, *bt, *cat_lb, *seq_cat_bt, *seq_hv, *bx;
	Evas_Object *cancel_button;
	static Winlist wl;
	
	//add background
	bg = elm_bg_add(set_seq);
	elm_win_resize_object_add(set_seq, bg);
	evas_object_size_hint_weight_set(bg, 1.0, 1.0);
	evas_object_show(bg);

	//add vbox
	vbox = elm_box_add(set_seq);
	elm_win_resize_object_add(set_seq, vbox);
	evas_object_size_hint_weight_set(vbox, 1.0, 1.0);
	evas_object_show(vbox);
	
	//add a frame
	fr = elm_frame_add(set_seq);
	elm_object_style_set(fr, "outdent_top");
	evas_object_size_hint_weight_set(fr, 0.0, 0.0);
	evas_object_size_hint_align_set(fr, 0.5, -1.0);
	elm_box_pack_end(vbox, fr);
	evas_object_show(fr);
	
	// add a label
	pref_lb = elm_label_add(set_seq);
	sprintf(ty, "Set %s Sequence", type);
	elm_label_label_set(pref_lb, ty);
	elm_frame_content_set(fr, pref_lb);
	evas_object_show(pref_lb);

	//if for apps add a category label and hover for categories
	if (strcmp(type, "Application")==0) {
		//add a hbox
		hbox = elm_box_add(set_seq);
		elm_box_homogenous_set(hbox, 1);
		elm_box_horizontal_set(hbox, 1);
		evas_object_size_hint_weight_set(hbox, 1.0, 0.0);
		evas_object_size_hint_align_set(hbox, -1.0, 0.0);
		elm_box_pack_end(vbox, hbox);
		evas_object_show(hbox);
		
		//add the app label
		cat_lb = elm_label_add(set_seq);
		elm_label_label_set(cat_lb, "Select Category");
		elm_box_pack_end(hbox, cat_lb);
		evas_object_show(cat_lb);
		
		//add the category hover
		seq_hv = elm_hover_add(set_seq);
		seq_cat_bt = elm_button_add(set_seq);
		elm_button_label_set(seq_cat_bt,"Category");
		evas_object_smart_callback_add(seq_cat_bt, "clicked", my_hover_bt_1, seq_hv);
		evas_object_size_hint_weight_set(seq_hv, 0.0, 0.0);
		evas_object_size_hint_align_set(seq_hv, 0.5, 0.0);
		elm_box_pack_end(hbox, seq_cat_bt);
		evas_object_show(seq_cat_bt);
		elm_hover_parent_set(seq_hv, set_seq);
		elm_hover_target_set(seq_hv, seq_cat_bt);

		bt = elm_button_add(set_seq);
		elm_button_label_set(bt, "Category");
		elm_hover_content_set(seq_hv, "middle", bt);
		evas_object_show(bt);

		bx = elm_box_add(set_seq);
		//add categories
		add_hs_items (set_seq, bx, bt, 0);
		evas_object_show(bx);
		elm_hover_content_set(seq_hv, "bottom", bx); 
	}
	//add a list
	seq_list = elm_genlist_add(set_seq);
	//elm_genlist_bounce_set(seq_list, 0, 0);
	evas_object_size_hint_weight_set(seq_list, 1.0, 1.0);
	evas_object_size_hint_align_set(seq_list, -1.0, -1.0);
	elm_list_multi_select_set(seq_list, 0);
	elm_box_pack_end(vbox, seq_list);
	evas_object_show(seq_list);
	evas_object_smart_callback_add(list, "selected", app_select, seq_list);

	//genlist class defs
	itc_seq_list.item_style     	= "default";
	itc_seq_list.func.label_get 	= gl_seq_label_get;
	itc_seq_list.func.icon_get  	= gl_seq_icon_get;
	itc_seq_list.func.state_get 	= gl_seq_state_get;
	itc_seq_list.func.del       	= gl_seq_del;

	//populate list
	populate_seq_list(seq_list, type);

	//add a hbox
	hbox = elm_box_add(set_seq);
	elm_box_homogenous_set(hbox, 1);
	elm_box_horizontal_set(hbox, 1);
	evas_object_size_hint_weight_set(hbox, 1.0, 0.0);
	evas_object_size_hint_align_set(hbox, -1.0, 0.0);
	elm_box_pack_end(vbox, hbox);
	evas_object_show(hbox);

	// add move up button
	bt = elm_button_add(set_seq);
	elm_button_label_set(bt, "/\\");
	evas_object_size_hint_weight_set(bt, 1.0, 1.0);
	evas_object_size_hint_align_set(bt, -1.0, 1.0);
	elm_box_pack_end(hbox, bt);
	evas_object_show(bt);
	evas_object_smart_callback_add(bt, "clicked", seq_move_up, type);
	
	// add move down button
	bt = elm_button_add(set_seq);
   	elm_button_label_set(bt, "\\/");	
	evas_object_size_hint_weight_set(bt, 1.0, 1.0);
	evas_object_size_hint_align_set(bt, -1.0, 1.0);
	elm_box_pack_end(hbox, bt);
	evas_object_show(bt);
	evas_object_smart_callback_add(bt, "clicked", seq_move_down, type);
	
	// add cancel button
	cancel_button = elm_button_add(set_seq);
	elm_button_label_set(cancel_button, "Done");
	evas_object_size_hint_weight_set(cancel_button, 1.0, 0.0);
	evas_object_size_hint_align_set(cancel_button, -1.0, 1.0);
	elm_box_pack_end(hbox, cancel_button);
	evas_object_show(cancel_button);
	wl.win = set_seq;
	wl.li = seq_list;
	evas_object_smart_callback_add(cancel_button, "clicked", done_clicked, &wl);
	
	//set delete callback for this window
	evas_object_smart_callback_add(set_seq, "delete-request", cancel_button_clicked, &wl);

	evas_object_resize(set_seq, 480, 600);	
	evas_object_show(set_seq);
}

void clock_back_clicked(void *user_data, Evas_Object *obj, const char *em, const char *src)
{
	time_t curtime, f_tm;
	struct tm *loctime;
	int day=0, diff=0, w_day=0, row=0, col=0;
	char mth[50], dt[4], ty[4];
	Evas_Object *cal, *tb, *inwin;
	cal = elm_win_add(NULL, "calendar", ELM_WIN_BASIC);
	elm_win_title_set(cal, "Calendar");
	elm_win_autodel_set(cal, 1);
	
	Evas_Object *bg, *vbox, *lb;
	Evas_Object *cancel_button;
	static Winlist wl;
	
	//add background
	bg = elm_bg_add(cal);
	elm_win_resize_object_add(cal, bg);
	evas_object_size_hint_weight_set(bg, 1.0, 1.0);
	evas_object_show(bg);

	//add an inwin
	inwin = elm_win_inwin_add(cal);
	elm_object_style_set(cal, "minimal_vertical");
	evas_object_show(inwin);
   
	//add vbox
	vbox = elm_box_add(cal);
	elm_win_inwin_content_set(inwin, vbox);
	evas_object_show(vbox);
		
	curtime = time (NULL);
	loctime = localtime (&curtime);
	//get current month
	strftime(mth, 50, "%B", loctime);
	
	//print month label on top
	lb = elm_label_add(cal);
	elm_label_label_set(lb, mth);
	elm_box_pack_end(vbox, lb);
	evas_object_show(lb);
		
	//get today date
	strftime(dt, 4, "%d", loctime);
	day = atoi(dt);

	//get weekday for 1st
	diff = 86400 * (day - 1);
	f_tm = curtime - diff;
	loctime = localtime (&f_tm);
	strftime(dt, 4, "%w", loctime);
	w_day = atoi(dt);

	//add a table
	tb = elm_table_add(cal);
	evas_object_size_hint_weight_set(tb, 1.0, 1.0);
	elm_table_homogenous_set(tb, 1);
	elm_box_pack_end(vbox, tb);
	evas_object_show(tb);

	//loop
	for (row=0; row <6; row++) {
		for (col=0; col<7; col++) {
			lb = elm_label_add(cal);
			if(row == 0) {
				//add the week day labels
				switch(col) {
					case 0 :	sprintf(ty, "Sun"); break;
					case 1 :	sprintf(ty, "Mon"); break;
					case 2 :	sprintf(ty, "Tue"); break;
					case 3 :	sprintf(ty, "Wed"); break;
					case 4 :	sprintf(ty, "Thu"); break;
					case 5 :	sprintf(ty, "Fri"); break;
					case 6 :	sprintf(ty, "Sat"); break;
				}
			}
			else if (row == 1){
				if (col < w_day) sprintf(ty, " ");
				else if (col == w_day) sprintf(ty , "01");
				else {
					sprintf(ty, "%02d", col - w_day + 1);
				}
			}
			else {
				if ((col - w_day + 1) + 7 * (row -1) < 32) {//cater for all months
					sprintf(ty, "%02d", (col - w_day + 1) + 7 * (row -1));
				}
				else sprintf(ty, " ");
			}
			elm_label_label_set(lb, ty);
			elm_table_pack(tb, lb, col, row, 1, 1);
			evas_object_show(lb);
		}
	}

	// add cancel button
	cancel_button = elm_button_add(cal);
	elm_button_label_set(cancel_button, "Done");
	evas_object_size_hint_weight_set(cancel_button, 1.0, 0.0);
	evas_object_size_hint_align_set(cancel_button, -1.0, 1.0);
	elm_box_pack_end(vbox, cancel_button);
	evas_object_show(cancel_button);
	wl.win = cal;
	wl.li = NULL;
	evas_object_smart_callback_add(cancel_button, "clicked", done_clicked, &wl);
	
	//set delete callback for this window
	evas_object_smart_callback_add(cal, "delete-request", cancel_button_clicked, &wl);
	
	evas_object_resize(cal, 480, 600);	
	evas_object_show(cal);
}

void show_prefs(void *data, Evas_Object *obj, void *event_info)
{
	Evas_Object *fr_hbox, *ic_fr, *box, *bt, *hbox, *pref_lb, *en_time, *en_date, *en_cb, *en_hs, *wall_button;
	Evas_Object *app_button, *sl, *tg;
	char *dt = (char *) data;

	get_brightness();

	//delete items in the vbox
	elm_box_clear(pref_vbox);
	//check for the group and add widgets in vbox depending on the group
	if(strcmp(dt, "Quick") == 0) { //create widgets for the quick part
		//add an hbox
		fr_hbox = elm_box_add(set_win);
		evas_object_size_hint_weight_set(fr_hbox, 1.0, 1.0);
		evas_object_size_hint_align_set(fr_hbox, -1.0, 0.0);
		elm_box_pack_end(pref_vbox, fr_hbox);
		evas_object_show(fr_hbox);

		//add a slider for brightness
		sl = elm_slider_add(set_win);
		elm_slider_span_size_set(sl, 110);
		evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
		evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5);
		elm_slider_label_set(sl, "Brightness");
		elm_slider_horizontal_set(sl, 1);
		elm_slider_min_max_set(sl, 0, 100);
		elm_slider_unit_format_set(sl, "%1.0f");
		elm_slider_value_set(sl, brightness);
		elm_box_pack_end(fr_hbox, sl);
		evas_object_show(sl);
		evas_object_smart_callback_add(sl, "delay,changed", set_brightness, sl);

		//add a toggle for bluetooth
		tg = elm_toggle_add(set_win);
		evas_object_size_hint_weight_set(tg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
		evas_object_size_hint_align_set(tg, EVAS_HINT_FILL, 0.5);
		elm_toggle_label_set(tg, "Bluetooth");
		//elm_toggle_icon_set(tg, ic);
		elm_toggle_state_set(tg, bt_st);
		elm_toggle_states_labels_set(tg, "On", "Off");
		elm_box_pack_end(fr_hbox, tg);
		evas_object_show(tg);
		//evas_object_show(ic);		
		evas_object_smart_callback_add(tg, "changed", bt_set, tg);
		
		//add a toggle for GSM
		tg = elm_toggle_add(set_win);
		evas_object_size_hint_weight_set(tg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
		evas_object_size_hint_align_set(tg, EVAS_HINT_FILL, 0.5);
		elm_toggle_label_set(tg, "GSM");
		//elm_toggle_icon_set(tg, ic);
		elm_toggle_state_set(tg, GSM_st);
		elm_toggle_states_labels_set(tg, "On", "Off");
		elm_box_pack_end(fr_hbox, tg);
		evas_object_show(tg);
		//evas_object_show(ic);
		evas_object_smart_callback_add(tg, "changed", gsm_set, tg);
		
		//add a toggle for GPS
		tg = elm_toggle_add(set_win);
		evas_object_size_hint_weight_set(tg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
		evas_object_size_hint_align_set(tg, EVAS_HINT_FILL, 0.5);
		elm_toggle_label_set(tg, "GPS");
		//elm_toggle_icon_set(tg, ic);
		elm_toggle_state_set(tg, GPS_st);
		elm_toggle_states_labels_set(tg, "On", "Off");
		elm_box_pack_end(fr_hbox, tg);
		evas_object_show(tg);
		//evas_object_show(ic);	
		evas_object_smart_callback_add(tg, "changed", gps_set, tg);
		
		//add a toggle for WiFi
		tg = elm_toggle_add(set_win);
		evas_object_size_hint_weight_set(tg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
		evas_object_size_hint_align_set(tg, EVAS_HINT_FILL, 0.5);
		elm_toggle_label_set(tg, "WiFi");
		//elm_toggle_icon_set(tg, ic);
		elm_toggle_state_set(tg, WiFi_st);
		elm_toggle_states_labels_set(tg, "On", "Off");
		elm_box_pack_end(fr_hbox, tg);
		evas_object_show(tg);
		//evas_object_show(ic);	
		evas_object_smart_callback_add(tg, "changed", wifi_set, tg);
		
		//add a toggle for airplane mode
		tg = elm_toggle_add(set_win);
		evas_object_size_hint_weight_set(tg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
		evas_object_size_hint_align_set(tg, EVAS_HINT_FILL, 0.5);
		elm_toggle_label_set(tg, "Airplane");
		//elm_toggle_icon_set(tg, ic);
		elm_toggle_state_set(tg, 0);
		elm_toggle_states_labels_set(tg, "On", "Off");
		elm_box_pack_end(fr_hbox, tg);
		evas_object_show(tg);
		//evas_object_show(ic);		
	}
	else if(strcmp(dt, "Apps") == 0) { //create widgets for the apps part
		//add an hbox
		fr_hbox = elm_box_add(set_win);
		elm_box_horizontal_set(fr_hbox, 1);
		evas_object_size_hint_weight_set(fr_hbox, 1.0, 0.0);
		evas_object_size_hint_align_set(fr_hbox, -1.0, 0.0);
		elm_box_pack_end(pref_vbox, fr_hbox);
		evas_object_show(fr_hbox);
	
		//add a frame
		ic_fr = elm_frame_add(set_win);
		elm_object_scale_set(ic_fr, 1.0);
		elm_object_style_set(ic_fr, "default");
		elm_frame_label_set(ic_fr, "Internal Apps");
		evas_object_size_hint_weight_set(ic_fr, 1.0, 0.0);
		evas_object_size_hint_align_set(ic_fr, -1.0, -1.0);
		elm_box_pack_end(fr_hbox, ic_fr);
		evas_object_show(ic_fr);

		//add a box
		box = elm_box_add(set_win);
		evas_object_size_hint_weight_set(box, 1.0, 0.0);
		evas_object_size_hint_align_set(box, -1.0, 0.0);
		elm_frame_content_set(ic_fr, box);
		evas_object_show(box);
	
		//add log check box 
		cb_log = elm_check_add(set_win);
		elm_check_label_set(cb_log, "Use Int Log");
		elm_box_pack_end(box, cb_log);
		elm_check_state_set(cb_log, int_log);
		evas_object_size_hint_weight_set(cb_log, 1.0, 0.0);
		evas_object_size_hint_align_set(cb_log, 0.0, 0.0);
		evas_object_show(cb_log);  
		evas_object_smart_callback_add(cb_log, "changed", cb_log_clicked, NULL);

		//add sms check box 
		cb_sms = elm_check_add(set_win);
		elm_check_label_set(cb_sms, "Use Int SMS");
		elm_box_pack_end(box, cb_sms);
		elm_check_state_set(cb_sms, int_sms);
		evas_object_size_hint_weight_set(cb_sms, 1.0, 0.0);
		evas_object_size_hint_align_set(cb_sms, 0.0, 0.0);
		evas_object_show(cb_sms);  
		evas_object_smart_callback_add(cb_sms, "changed", cb_sms_clicked, NULL);

		//add contacts check box 
		cb_con = elm_check_add(set_win);
		elm_check_label_set(cb_con, "Use Int Contacts");
		elm_box_pack_end(box, cb_con);
		elm_check_state_set(cb_con, int_con);
		evas_object_size_hint_weight_set(cb_con, 1.0, 0.0);
		evas_object_size_hint_align_set(cb_con, 0.0, 0.0);
		evas_object_show(cb_con);  
		evas_object_smart_callback_add(cb_con, "changed", cb_con_clicked, NULL);

		//add a frame
		ic_fr = elm_frame_add(set_win);
		elm_object_scale_set(ic_fr, 1.0);
		elm_object_style_set(ic_fr, "default");
		elm_frame_label_set(ic_fr, "Int Apps Data");
		evas_object_size_hint_weight_set(ic_fr, 1.0, 0.0);
		evas_object_size_hint_align_set(ic_fr, -1.0, -1.0);
		elm_box_pack_end(fr_hbox, ic_fr);
		evas_object_show(ic_fr);

		//add a box
		box = elm_box_add(set_win);
		evas_object_size_hint_weight_set(box, 1.0, 0.0);
		evas_object_size_hint_align_set(box, -1.0, 0.0);
		elm_frame_content_set(ic_fr, box);
		evas_object_show(box);

		//add rescan contacts button
		bt = elm_button_add(set_win);
		elm_button_label_set(bt, "Rescan Contacts");
		evas_object_size_hint_weight_set(bt, 1.0, 1.0);
		evas_object_size_hint_align_set(bt, -1.0, 0.0);
		elm_box_pack_end(box, bt);
		evas_object_show(bt);
		evas_object_smart_callback_add(bt, "clicked", rescan_contacts, NULL);

		//add rescan sms button
		bt = elm_button_add(set_win);
		elm_button_label_set(bt, "Rescan SMS");
		evas_object_size_hint_weight_set(bt, 1.0, 1.0);
		evas_object_size_hint_align_set(bt, -1.0, 0.0);
		elm_box_pack_end(box, bt);
		evas_object_show(bt);
		evas_object_smart_callback_add(bt, "clicked", rescan_sms, NULL);

		//add rescan calls button
		bt = elm_button_add(set_win);
		elm_button_label_set(bt, "Rescan Calls");
		evas_object_size_hint_weight_set(bt, 1.0, 1.0);
		evas_object_size_hint_align_set(bt, -1.0, 0.0);
		elm_box_pack_end(box, bt);
		evas_object_show(bt);
		evas_object_smart_callback_add(bt, "clicked", rescan_calls, NULL);

		//add a frame
		ic_fr = elm_frame_add(set_win);
		elm_object_scale_set(ic_fr, 1.0);
		elm_object_style_set(ic_fr, "default");
		elm_frame_label_set(ic_fr, "Icon Sequence");
		evas_object_size_hint_weight_set(ic_fr, 1.0, 0.0);
		evas_object_size_hint_align_set(ic_fr, -1.0, -1.0);
		elm_box_pack_end(pref_vbox, ic_fr);
		evas_object_show(ic_fr);

		//add a box
		box = elm_box_add(set_win);
		evas_object_size_hint_weight_set(box, 1.0, 0.0);
		evas_object_size_hint_align_set(box, -1.0, 0.0);
		elm_frame_content_set(ic_fr, box);
		evas_object_show(box);

		//add set app seq button
		bt = elm_button_add(set_win);
		elm_button_label_set(bt, "App Icons");
		evas_object_size_hint_weight_set(bt, 1.0, 1.0);
		evas_object_size_hint_align_set(bt, -1.0, 0.0);
		elm_box_pack_end(box, bt);
		evas_object_show(bt);
		evas_object_smart_callback_add(bt, "clicked", (void *)set_seq_page, (char *)"Application");

		//add add category button
		app_button = elm_button_add(set_win);
		elm_button_label_set(app_button, "Set App Categories");
		evas_object_size_hint_weight_set(app_button, 1.0, 1.0);
		evas_object_size_hint_align_set(app_button, -1.0, -1.0);
		elm_box_pack_end(pref_vbox, app_button);
		evas_object_show(app_button);
		evas_object_smart_callback_add(app_button, "clicked", app_button_clicked, NULL);
	}
	else if(strcmp(dt, "Date") == 0) { //create widgets for the Date part
		//add an hbox
		fr_hbox = elm_box_add(set_win);
		elm_box_horizontal_set(fr_hbox, 1);
		evas_object_size_hint_weight_set(fr_hbox, 1.0, 0.0);
		evas_object_size_hint_align_set(fr_hbox, -1.0, 0.0);
		elm_box_pack_end(pref_vbox, fr_hbox);
		evas_object_show(fr_hbox);
		
		//add a frame
		ic_fr = elm_frame_add(set_win);
		elm_object_scale_set(ic_fr, 1.0);
		elm_object_style_set(ic_fr, "default");
		elm_frame_label_set(ic_fr, "Date/Time Format");
		evas_object_size_hint_weight_set(ic_fr, 0.0, 0.0);
		evas_object_size_hint_align_set(ic_fr, 0.0, -1.0);
		elm_box_pack_end(fr_hbox, ic_fr);
		evas_object_show(ic_fr);

		//add a box
		box = elm_box_add(set_win);
		evas_object_size_hint_weight_set(box, 1.0, 0.0);
		evas_object_size_hint_align_set(box, -1.0, 0.0);
		elm_frame_content_set(ic_fr, box);
		evas_object_show(box);

		//add a hbox
		hbox = elm_box_add(set_win);
		elm_box_horizontal_set(hbox, 1);
		evas_object_size_hint_weight_set(hbox, 1.0, 0.0);
		evas_object_size_hint_align_set(hbox, -1.0, 0.0);
		elm_box_pack_end(box, hbox);
		evas_object_show(hbox);

		//add a label
		pref_lb = elm_label_add(set_win);
		elm_label_label_set(pref_lb, "Time: ");
		elm_box_pack_end(hbox, pref_lb);
		evas_object_show(pref_lb);  
	
		//add an entry
		en_time = elm_entry_add(set_win);
		elm_entry_entry_set(en_time, f_time);
		evas_object_size_hint_weight_set(en_time, 1.0, 1.0);
		evas_object_size_hint_align_set(en_time, -1.0, 0.5);
		elm_box_pack_end(hbox, en_time);
		evas_object_show(en_time);

		//add a hbox
		hbox = elm_box_add(set_win);
		elm_box_horizontal_set(hbox, 1);
		evas_object_size_hint_weight_set(hbox, 1.0, 0.0);
		evas_object_size_hint_align_set(hbox, -1.0, 0.0);
		elm_box_pack_end(box, hbox);
		evas_object_show(hbox);

		//add a label
		pref_lb = elm_label_add(set_win);
		elm_label_label_set(pref_lb, "Date: ");
		elm_box_pack_end(hbox, pref_lb);
		evas_object_show(pref_lb);  
	
		//add an entry
		en_date = elm_entry_add(set_win);
		elm_entry_entry_set(en_date, f_date);
		evas_object_size_hint_weight_set(en_date, 1.0, 1.0);
		evas_object_size_hint_align_set(en_date, -1.0, 0.5);
		elm_box_pack_end(hbox, en_date);
		evas_object_show(en_date);
	
		//add a hbox
		hbox = elm_box_add(set_win);
		elm_box_horizontal_set(hbox, 1);
		elm_box_homogenous_set(hbox, 1);
		evas_object_size_hint_weight_set(hbox, 1.0, 0.0);
		evas_object_size_hint_align_set(hbox, -1.0, 0.0);
		elm_box_pack_end(box, hbox);
		evas_object_show(hbox);

		//add add category button
		bt = elm_button_add(set_win);
		elm_button_label_set(bt, "Set Time Format");
		evas_object_size_hint_weight_set(bt, 1.0, 1.0);
		evas_object_size_hint_align_set(bt, -1.0, -1.0);
		elm_box_pack_end(hbox, bt);
		evas_object_show(bt);
		evas_object_smart_callback_add(bt, "clicked", set_time_format, en_time);

		//add change button
		bt = elm_button_add(set_win);
		elm_button_label_set(bt, "Set Date Format");
		evas_object_size_hint_weight_set(bt, 1.0, 1.0);
		evas_object_size_hint_align_set(bt, -1.0, -1.0);
		elm_box_pack_end(hbox, bt);
		evas_object_show(bt);
		evas_object_smart_callback_add(bt, "clicked", set_date_format, en_date);
	}
	else if(strcmp(dt, "General") == 0) { //create widgets for the General part
		//add an hbox
		fr_hbox = elm_box_add(set_win);
		elm_box_horizontal_set(fr_hbox, 1);
		evas_object_size_hint_weight_set(fr_hbox, 1.0, 0.0);
		evas_object_size_hint_align_set(fr_hbox, -1.0, 0.0);
		elm_box_pack_end(pref_vbox, fr_hbox);
		evas_object_show(fr_hbox);

		//add a frame
		ic_fr = elm_frame_add(set_win);
		elm_object_scale_set(ic_fr, 1.0);
		elm_object_style_set(ic_fr, "default");
		elm_frame_label_set(ic_fr, "Cell Broadcast");
		evas_object_size_hint_weight_set(ic_fr, 0.0, 0.0);
		evas_object_size_hint_align_set(ic_fr, 0.0, -1.0);
		elm_box_pack_end(fr_hbox, ic_fr);
		evas_object_show(ic_fr);

		//add a box
		box = elm_box_add(set_win);
		evas_object_size_hint_weight_set(box, 1.0, 0.0);
		evas_object_size_hint_align_set(box, -1.0, 0.0);
		elm_frame_content_set(ic_fr, box);
		evas_object_show(box);

		//add a hbox
		hbox = elm_box_add(set_win);
		elm_box_horizontal_set(hbox, 1);
		elm_box_homogenous_set(hbox, 1);
		evas_object_size_hint_weight_set(hbox, 1.0, 0.0);
		evas_object_size_hint_align_set(hbox, -1.0, 0.0);
		elm_box_pack_end(box, hbox);
		evas_object_show(hbox);
	
		//add a label
		pref_lb = elm_label_add(set_win);
		elm_label_label_set(pref_lb, "Channels: ");
		evas_object_size_hint_weight_set(pref_lb, 0.0, 1.0);
		evas_object_size_hint_align_set(pref_lb, 0.0, -1.0);
		elm_box_pack_end(hbox, pref_lb);
		evas_object_show(pref_lb);  

		//add an entry
		en_cb = elm_entry_add(set_win);
		elm_entry_entry_set(en_cb, cb_subs);
		evas_object_size_hint_weight_set(en_cb, 1.0, 1.0);
		evas_object_size_hint_align_set(en_cb, -1.0, 0.5);
		elm_box_pack_end(hbox, en_cb);
		evas_object_show(en_cb);

		//add sms check box 
		cb_channel = elm_check_add(set_win);
		elm_check_label_set(cb_channel, "Show Channel no");
		elm_box_pack_end(box, cb_channel);
		elm_check_state_set(cb_channel, show_c_no);
		evas_object_size_hint_weight_set(cb_channel, 1.0, 0.0);
		evas_object_size_hint_align_set(cb_channel, 0.0, 0.0);
		evas_object_show(cb_channel);  
		evas_object_smart_callback_add(cb_channel, "changed", cb_channel_clicked, NULL);
		
		//add add category button
		bt = elm_button_add(set_win);
		elm_button_label_set(bt, "Set Channels");
		evas_object_size_hint_weight_set(bt, 1.0, 1.0);
		evas_object_size_hint_align_set(bt, -1.0, -1.0);
		elm_box_pack_end(box, bt);
		evas_object_show(bt);
		evas_object_smart_callback_add(bt, "clicked", set_cb_subs, en_cb);
	
		//add a frame
		ic_fr = elm_frame_add(set_win);
		elm_object_scale_set(ic_fr, 1.0);
		elm_object_style_set(ic_fr, "default");
		elm_frame_label_set(ic_fr, "On Resume Headet");
		evas_object_size_hint_weight_set(ic_fr, 1.0, 0.0);
		evas_object_size_hint_align_set(ic_fr, -1.0, -1.0);
		elm_box_pack_end(fr_hbox, ic_fr);
		evas_object_show(ic_fr);

		//add a box
		box = elm_box_add(set_win);
		evas_object_size_hint_weight_set(box, 1.0, 0.0);
		evas_object_size_hint_align_set(box, -1.0, 0.0);
		elm_frame_content_set(ic_fr, box);
		evas_object_show(box);
	
		//add an hbox
		hbox = elm_box_add(set_win);
		elm_box_horizontal_set(hbox, 1);
		evas_object_size_hint_weight_set(hbox, 1.0, 0.0);
		evas_object_size_hint_align_set(hbox, -1.0, 0.0);
		elm_box_pack_end(box, hbox);
		evas_object_show(hbox);
	
		//add a label
		pref_lb = elm_label_add(set_win);
		elm_label_label_set(pref_lb, "Address: ");
		elm_box_pack_end(hbox, pref_lb);
		evas_object_show(pref_lb);  
	
		//add an entry
		en_hs = elm_entry_add(set_win);
		elm_entry_entry_set(en_hs, hs_add);
		evas_object_size_hint_weight_set(en_hs, 1.0, 1.0);
		evas_object_size_hint_align_set(en_hs, -1.0, 0.5);
		elm_box_pack_end(hbox, en_hs);
		evas_object_show(en_hs);
	
		//add sms check box 
		cb_hs = elm_check_add(set_win);
		elm_check_label_set(cb_hs, "AutoConnect");
		elm_box_pack_end(box, cb_hs);
		elm_check_state_set(cb_hs, show_c_no);
		evas_object_size_hint_weight_set(cb_hs, 1.0, 0.0);
		evas_object_size_hint_align_set(cb_hs, 0.0, 0.0);
		evas_object_show(cb_hs);  
		evas_object_smart_callback_add(cb_hs, "changed", cb_hs_clicked, NULL);

		//add a button
		bt = elm_button_add(set_win);
		elm_button_label_set(bt, "Set");
		evas_object_size_hint_weight_set(bt, 0.0, 1.0);
		evas_object_size_hint_align_set(bt, -1.0, -1.0);
		elm_box_pack_end(box, bt);
		evas_object_show(bt);
		evas_object_smart_callback_add(bt, "clicked", set_bt_add, en_hs);
		
		//add a hbox
		hbox = elm_box_add(set_win);
		elm_box_horizontal_set(hbox, 1);
		elm_box_homogenous_set(hbox, 1);
		evas_object_size_hint_weight_set(hbox, 1.0, 0.0);
		evas_object_size_hint_align_set(hbox, -1.0, 0.0);
		elm_box_pack_end(pref_vbox, hbox);
		evas_object_show(hbox);
	
		//add change button
		wall_button = elm_button_add(set_win);
		elm_button_label_set(wall_button, "Set Wallpaper");
		evas_object_size_hint_weight_set(wall_button, 1.0, 1.0);
		evas_object_size_hint_align_set(wall_button, -1.0, -1.0);
		elm_box_pack_end(hbox, wall_button);
		evas_object_show(wall_button);
		evas_object_smart_callback_add(wall_button, "clicked", create_dir_browser_page, NULL);
	}
}

char *notify_label_get(const void *data, Evas_Object *obj, const char *part)
{
	/*char *_cat = (char *)data;
	char *ty = strdup(_cat);
	return (ty);*/
	return(strdup(data));
}

Evas_Object *notify_icon_get(const void *data, Evas_Object *obj, const char *part)
{
	return NULL;
}

Eina_Bool notify_state_get(const void *data, Evas_Object *obj, const char *part)
{
	return 0;
}

void notify_del (const void *data, Evas_Object *obj)
{
}

void show_notifications(void)
{
	Evas_Object *bg, *notify_win, *vbox, *hbox, *notify_list, *bt;
	static Winlist wl;
	
	notify_win = elm_win_add(NULL, "notify", ELM_WIN_BASIC);
	elm_win_title_set(notify_win, "Notifications");
	printf("in notify win\n");
	//add background
	bg = elm_bg_add(notify_win);
	elm_win_resize_object_add(notify_win, bg);
	evas_object_size_hint_weight_set(bg, 1.0, 1.0);
	evas_object_show(bg);

	//add vbox 
	vbox = elm_box_add(notify_win);
	elm_win_resize_object_add(notify_win, vbox);
	evas_object_size_hint_weight_set(vbox, 1.0, 1.0);
	evas_object_show(vbox);
	
	//add list to vbox now
	notify_list = elm_genlist_add(notify_win);
	elm_genlist_bounce_set(notify_list, 0, 0);
	evas_object_size_hint_weight_set(notify_list, 1.0, 1.0);
	evas_object_size_hint_align_set(notify_list, -1.0, -1.0);
	elm_list_multi_select_set(notify_list, 0);
	elm_box_pack_end(vbox, notify_list);
	evas_object_show(notify_list);
	//evas_object_smart_callback_add(cat_list, "clicked", cat_list_selected, cat_list);

	//genlist class defs
	notify_itc.item_style     	= "default";
	notify_itc.func.label_get 	= notify_label_get;
	notify_itc.func.icon_get  	= notify_icon_get;
	notify_itc.func.state_get 	= notify_state_get;
	notify_itc.func.del      	= notify_del;

	add_notifications(notify_list);
	
	//add an hbox
	hbox = elm_box_add(notify_win);
	elm_box_horizontal_set(hbox, 1);
	evas_object_size_hint_weight_set(hbox, 1.0, 0.0);
	evas_object_size_hint_align_set(hbox, -1.0, 0.0);
	elm_box_pack_end(vbox, hbox);
	evas_object_show(hbox);

	//add clear notifications button
	bt = elm_button_add(notify_win);
	elm_button_label_set(bt, "Clear All");
	evas_object_size_hint_weight_set(bt, 0.0, 1.0);
	evas_object_size_hint_align_set(bt, -1.0, -1.0);
	elm_box_pack_end(vbox, bt);
	evas_object_show(bt);
	//evas_object_smart_callback_add(bt, "clicked", set_bt_add, en_hs);
	
	//add cancel button
	bt = elm_button_add(notify_win);
	elm_button_label_set(bt, "Close");
	evas_object_size_hint_weight_set(bt, 0.0, 1.0);
	evas_object_size_hint_align_set(bt, -1.0, -1.0);
	elm_box_pack_end(vbox, bt);
	evas_object_show(bt);
	wl.win = set_win;
	wl.li = NULL;
	evas_object_smart_callback_add(bt, "clicked", cancel_button_clicked, &wl);
	
	//set delete callback for this window
	evas_object_smart_callback_add(set_win, "delete-request", cancel_button_clicked, &wl);
	
	evas_object_resize(notify_win, 480, 600);	
	evas_object_show(notify_win);
}
